﻿using System;
using UnityEngine;

namespace Jacky
{
    public class CoreGameManager : MonoBehaviour
    {
        [SerializeField]
        private int Width =8;

        [SerializeField]
        private int Height = 8;

        [SerializeField]
        private int LandMineCount = 5;

        [SerializeField]
        private Transform uiParent;

        private readonly NodeManager _nodeManager = new NodeManager();


        private void Start()
        {
            Init();
        }

        private void Init()
        {
            _nodeManager.OnSuccessEvent += Win;
            _nodeManager.OnClickLandNode += Lost;
        }
        
        public void StartGame()
        {
            _nodeManager.Spawn(Width, Height, LandMineCount, uiParent);
           
        }

        public void ReStartGame()
        {
            _nodeManager.ReSet(Width,Height,LandMineCount,uiParent);
        }

        public void ExitGame()
        {
            _nodeManager.Dispose();
        }

        public void Win()
        {
            
        }

        public void Lost(AbstractNode node)
        {
            
        }

        private void OnGUI()
        {
            if (GUILayout.Button("开始游戏"))
            {
                StartGame();
            }

            if (GUILayout.Button("重新开始游戏"))
            {
                ReStartGame();
            }

            if (GUILayout.Button("退出游戏"))
            {
                ExitGame();
            }
        }
    }
}